import request from '@/utils/request';

export function getGoodsCategoryList() {
    return request({
        url: '/v1/goods/category/queryList',
        method: 'post',
        data: {}
    });
}

export function getGoodsSmallCountList(categoryId, { pageNum, pageSize }) {
    return request({
        url: '/v1/goods/category/goods',
        method: 'post',
        data: {
            categoryId,
            countSql: true,
            pageNum,
            pageSize,
            pageSizeZero: true,
            reasonable: true
        }
    });
}

// 创建大类
export function createGoodsCategory({ id, imageUrl, name, parentId, sortNo }) {
    return request({
        url: '/v1/goods/category/create',
        method: 'post',
        data: {
            imageUrl,
            name,
            // parentId,
            sortNo
        }
    });
}

// 创建小类
export function createSmallGoodsCategory({ id, imageUrl, name, parentId, sortNo }) {
    return request({
        url: '/v1/goods/category/create',
        method: 'post',
        data: {
            imageUrl,
            name,
            parentId,
            sortNo
        }
    });
}

// 更新商品大类信息
export function updateGoodsCategory({ id, imageUrl, name, parentId, sortNo }) {
    return request({
        url: `/v1/goods/category/update`,
        method: 'post',
        data: {
            id,
            imageUrl,
            name
            // parentId,
            // sortNo
        }
    });
}

// 更新商品小类信息
export function updateSmallGoodsCategory({ id, imageUrl, name, parentId, sortNo }) {
    return request({
        url: `/v1/goods/category/update`,
        method: 'post',
        data: {
            id,
            // imageUrl,
            name,
            parentId
            // sortNo
        }
    });
}

export function deleteGoodsCategory(id) {
    return request({
        url: `/v1/goods/category/delete/${id}`,
        method: 'delete'
    });
}

export function deleteGoodFromCategory(goodsId, categoryId) {
    return request({
        url: '/v1/goods/category/goods/delete',
        method: 'delete',
        data: {
            goodsId,
            categoryId
        }
    });
}
